package com.snpic.appaw.module.insure.controller.app.cxImage;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.snpic.appaw.framework.common.pojo.PageParam;
import com.snpic.appaw.framework.common.pojo.PageResult;
import com.snpic.appaw.framework.common.pojo.CommonResult;
import com.snpic.appaw.framework.common.util.object.BeanUtils;
import static com.snpic.appaw.framework.common.pojo.CommonResult.success;

import com.snpic.appaw.framework.excel.core.util.ExcelUtils;

import com.snpic.appaw.framework.apilog.core.annotation.ApiAccessLog;
import static com.snpic.appaw.framework.apilog.core.enums.OperateTypeEnum.*;

import com.snpic.appaw.module.insure.controller.app.cxImage.vo.*;
import com.snpic.appaw.module.insure.dal.dataobject.cxImage.CxImageDO;
import com.snpic.appaw.module.insure.service.cxImage.CxImageService;

@Tag(name = "C端 - 车险-影像")
@RestController
@RequestMapping("/insure/cx-image")
@Validated
public class AppCxImageController {

    @Resource
    private CxImageService cxImageService;

    @PostMapping("/create")
    @Operation(summary = "创建影像")
    public CommonResult<Long> createCxImageDO(@Valid @RequestBody AppCxImageDOSaveReqVO createReqVO) {
        return success(cxImageService.createCxImageDO(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新影像")
    public CommonResult<Boolean> updateCxImageDO(@Valid @RequestBody AppCxImageDOSaveReqVO updateReqVO) {
        cxImageService.updateCxImageDO(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除影像")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCxImageDO(@RequestParam("id") Long id) {
        cxImageService.deleteCxImageDO(id);
        return success(true);
    }

//    @DeleteMapping("/delete-list")
//    @Parameter(name = "ids", description = "编号", required = true)
//    @Operation(summary = "批量删除车险-影像")
    public CommonResult<Boolean> deleteCxImageDOList(@RequestParam("ids") List<Long> ids) {
        cxImageService.deleteCxImageDOListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得车险影像")
    @Parameter(name = "id", description = "ID", required = true)
    public CommonResult<AppCxImageDORespVO> getCxImageDO(@RequestParam("id") Long id) {
        CxImageDO cxImageDO = cxImageService.getCxImageDO(id);
        return success(BeanUtils.toBean(cxImageDO, AppCxImageDORespVO.class));
    }

//    @GetMapping("/page")
//    @Operation(summary = "获得车险-影像分页")
    public CommonResult<PageResult<AppCxImageDORespVO>> getCxImageDOPage(@Valid AppCxImageDOPageReqVO pageReqVO) {
        PageResult<CxImageDO> pageResult = cxImageService.getCxImageDOPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppCxImageDORespVO.class));
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出车险-影像 Excel")
//    @ApiAccessLog(operateType = EXPORT)
    public void exportCxImageDOExcel(@Valid AppCxImageDOPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<CxImageDO> list = cxImageService.getCxImageDOPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "车险-影像.xls", "数据", AppCxImageDORespVO.class,
                        BeanUtils.toBean(list, AppCxImageDORespVO.class));
    }

}